import { LoadingInstance } from 'element-plus/es/components/loading/src/loading';
import { previewReport, previewEvidence } from '@/api/xydz/history/index';

const baseURL = import.meta.env.VITE_APP_BASE_PREVIEW_URL;
let previewLoadingInstance: LoadingInstance;
export default {
  async oss(ossId: string) {
    previewLoadingInstance = ElLoading.service({ text: '正在处理数据，请稍候', background: 'rgba(0, 0, 0, 0.7)' });
    try {
      const res = await previewEvidence(ossId);
      //新开页打开预览地址
      let url = res.data;
      url = url.replace('http://22.167.163.10:9000', baseURL);
      window.open(url, '_blank');
      previewLoadingInstance.close();
    } catch (r) {
      ElMessage.error('预览文件出现错误，请联系管理员！');
      previewLoadingInstance.close();
    }
  },
  async report(reportId: string) {
    previewLoadingInstance = ElLoading.service({ text: '正在处理数据，请稍候', background: 'rgba(0, 0, 0, 0.7)' });
    try {
      const res = await previewReport(reportId);
      //新开页打开预览地址
      let url = res.data;
      url = url.replace('http://22.167.163.10:9000', baseURL);
      window.open(url, '_blank');
      previewLoadingInstance.close();
    } catch (r) {
      ElMessage.error('预览文件出现错误，请联系管理员！');
      previewLoadingInstance.close();
    }
  }
};
